<?php

define('CHECKWORD_SECRET', 'age@$3402$9t,i3$^#23');
define('PASSWORD_SECRET1', 'sd*n9w8@$@AFy389ry@$');
define('PASSWORD_SECRET2', 'sd@$$g43lks@$&*32893');
define('USER_ATTEMPS2AUTHORIZE', 3);

class UserModule extends CWebModule{
    
    public $emailSender = null;
    public $auth;
    public $reg = array(
        'activate_after_reg' => 'email' // требовать активацию пользователя после регистрации [false, email, admin]
    );
    
    public function init(){
        $this->setImport(array(
            'user.models.*',
            'user.components.*',
        ));
        if(is_null($this->emailSender)){
            $this->emailSender = array('user@'.$_SERVER['HTTP_HOST']=>'Почтовик-Мочтовик');
        }
    }
    
    public function beforeControllerAction($controller, $action){
        if(parent::beforeControllerAction($controller, $action)){
            return true;
        }else
            return false;
    }
    
    public static function t($type, $message){
        return Yii::t('UserModule.'.$type,$message);
    }
    
    public static function url($route, $params=array(), $backurl=false){
        if($backurl){
            if(isset($_GET['backurl'])){
                $params['backurl'] = urldecode($_GET['backurl']);
            }else{
                $url = $_SERVER['REQUEST_URI'];
                $url = parse_url($url);
                if(isset($url['query']) and !empty($url['query'])){
                    parse_str($url['query'], $q);
                    if(isset($q['backurl'])) unset($q['backurl']);
                    $url = $url['path'];
                    if(!empty($q)) $url .= '?'.http_build_query($q);
                }else{
                    $url = $url['path'];
                }
                $params['backurl'] = $url;
            }
        }
        return Yii::app()->getController()->createUrl($route, $params);
    }
    
}
